<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Drag File and Drop it</title>
    <style>
        .drop-area {
            width: 300px;
            height: 200px;
            border: 2px dashed #ccc;
        }
    </style>
</head>
<body>
    <h1>Drag File and Drop it</h1>

    <section class="note">
        <p>必须要监听 drop  和 dragover 事件， 可以用属性监听 (ondrop / ondragover) 或 addEventListener监听</p>
    </section>
    <!-- <div class="drop-area" ondrop="dropCallback(event)" ondragover="dragOverCallback(event)">
        drop file here
    </div> -->
    <div class="drop-area" >
        drop file here 2
    </div>

    <script>
        function $(s) {
            return document.querySelector(s);
        }

        const dropAreaDiv = $('.drop-area');
        function dropCallback(e) {
            e.preventDefault();
            e.stopPropagation();
            const files = e.dataTransfer.files;
            console.log(files);
        }

        function dragOverCallback(e) {
            e.preventDefault();
            e.stopPropagation();
        }

        dropAreaDiv.addEventListener('dragover', dragOverCallback)
        dropAreaDiv.addEventListener('drop', dropCallback)
    </script>
</body>
</html>